<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>MPCController</title>
<style type="text/css">
	body {background-color: white; color: black; font-family:sans-serif; font-size:medium;}
	a:link {color: #3300ff;}
	a:visited {color: #663399;}
	a:hover {color:#0099ff;}
	a:active {color: #0066cc;}
	a.button {text-decoration:none;}
	
	table.nav  {background-color: #dbddff;}
	table.body {margin-top:2ex; margin-bottom:2ex;}
	table.programlistingindent {margin-left:32px;}
	
	img { margin-bottom:0px; margin-top:0px;}
	tt {margin-left:0.5em; margin-right:0.5em; font-weight:lighter;}
	
	p {margin-top:0ex;}
	p.synopsis {margin-left:32px;}
	p.programlistingindent {margin-left:32px;}
	p.citetitle {margin-left:2em;}
	
	ul ul {list-style-type:square;}
	ul li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	ol li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	
	h1.reftitle {color:#a90000;}
	h1.reftitle {font-size:3.7ex; margin-top:0; margin-bottom:0; font-weight:bold}
	h1.title {color:black; font-size:4ex; margin-top:1ex; font-weight:bold}
	h2.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:3ex}
	h3.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h4.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex}
	h2 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h3 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex} 
	
	pre.programlisting {margin-left:32px;}
	pre.synopsis {margin-left:32px;}
	
	
	.categorytitle {margin-top:8px; padding-top:0px;}
	.categorylist {background-color: #e1e6f2;}
 	</style>
</head>
<body>
<a name="top_of_page"></a><p style="font-size:1px;"></p>
<h1 class="reftitle">MPCController</h1>
<h2>Purpose</h2>
<p>MPC controller with on-line optimization</p>
<h2>Syntax</h2>
<pre class="synopsis">ctrl = MPCController(model)</pre>
<pre class="synopsis">ctrl = MPCController(model, horizon)</pre>
<h2>Description</h2>
<p></p> 
    
      <tt>ctrl = MPCController(model)</tt> constructs an MPC
    optimization problem by using the object <tt>model</tt> as the
    prediction model.<br><br>

    The basic optimization problem takes the following form:
    <p class="programlistingindent"><img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller20.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller20.png"></p>
    where <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller1.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller1.png"> is the prediction horizon, <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller2.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller2.png">, <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller3.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller3.png">,
    <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller4.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller4.png"> are the state, input, and output predictions,
    respectively, <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller5.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller5.png"> denotes the terminal cost,
    <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller6.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller6.png"> is the stage cost, <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller7.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller7.png">
    represents the state-update equation, and <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller8.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller8.png"> is
    the output equation.<br><br>

    The terminal cost is given by <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller9.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller9.png">, where
    <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller10.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller10.png"> is the weighting matrix and <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller11.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller11.png"> is the type of the
    norm (if <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller12.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller12.png">, then <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller13.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller13.png">, see
    "<tt>help Function</tt>" for more information). The type
    of the norm as well as the weighting matrix are specified by the
    <tt>terminalPenalty</tt> property of the state signal (see
    "<tt>help SystemSignal/filter_terminalPenalty</tt>").<br><br>

    The stage cost is represented by <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller14.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller14.png">, where
    <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller15.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller15.png"> are weighting matrices and <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller16.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller16.png"> represent types
    of the norms. Properties of the state penalization are taken from
    <tt>model.x.penalty</tt> (see "<tt>help
    SystemSignal/filter_penalty</tt>"). Similarly, properties of input
    and output penalizations are extracted from
    <tt>model.u.penalty</tt> and <tt>model.y.penalty</tt>,
    respectively. Note that different norms/weights can be assigned to
    various signals. Hence you can have a quadratic penalization of
    the state, but use a 1-norm penalty on the inputs.<br><br>

    If a certain signal (state, input, and/or output) has the
    <tt>reference</tt> filter enabled (see "<tt>help
    SystemSignal/filter_reference</tt>"), the terminal and stage costs
    become <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller17.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller17.png"> and <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller18.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller18.png">. If some
    signal does not have the <tt>reference</tt> property enabled, we
    assume a zero reference instead.<br><br>

    By default, min/max bounds on state, input, and output variables
    are added to the MPC setup. The bounds stored in
    <tt>model.x.min</tt>, <tt>model.x.max</tt>, <tt>model.u.min</tt>, 
    <tt>model.u.max</tt>, <tt>model.y.min</tt>, and
    <tt>model.y.max</tt> are used. Note that other types of
    constraints can be added. These include polyhedral constraints
    (see "<tt>help SystemSignal/filter_setConstraint</tt>"), soft
    constraints (see "<tt>help SystemSignal/filter_softMax</tt>" and
    "<tt>help SystemSignal/filter_softMin</tt>"), or move blocking (see
    "<tt>help SystemSignal/filter_block</tt>").<br><br>

    The basic way to create an MPC controller is to call<br><br>

    
      <tt>controller = MPCController(system)</tt>
      <br><br>

    where <tt>system</tt> represents the dynamical system to be used
    for predictions (can be an
    instance of the <tt>LTISystem</tt>, <tt>PWASystem</tt>, or
    <tt>MLDSystem</tt> classes). Then you can further fine-tune the
    prediction model by adding constraints and/or modifying
    penalties. This can be done by accessing the <tt>model</tt>
    property of the controller object:<br><br>

    
      <tt>controller.model.x.min = [-5; -5]</tt>
      <br><br>
 
    You can also specify the prediction horizon directly from the
    command line:<br><br>
    
    
      <tt>controller.N = 3</tt>
      <br><br>

    Once the controller is fully specified, you can use the
    <tt>evaluate</tt> method to obtain the optimal sequence of inputs,
    (see "<tt>help MPCController/evaluate</tt>"), or compute the
    explicit form of the controller by calling the <tt>toExplicit</tt>
    method (see "<tt>help MPCController/toExplicit</tt>").
  <h2>Input Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody>
<tr valign="top">
<td><tt>model</tt></td>
<td>
<p></p>Any MPT3 system (<tt>LTISystem</tt>, <tt>PWASystem</tt>,
      <tt>MLDSystem</tt>)<p>
	    		Class: <tt>AbstractSystem</tt></p>
</td>
</tr>
<tr valign="top">
<td><tt>N</tt></td>
<td>
<p></p>Prediction horizon<p>
	    		Class: <tt>Double</tt></p>
</td>
</tr>
</tbody>
</table>
<h2>Output Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody><tr valign="top">
<td><tt>controller</tt></td>
<td>
<p></p>Instance of the <tt>MPCController</tt> class.</td>
</tr></tbody>
</table>
<h2>Example(s)</h2>
<h3>Example 
				1</h3>Create a 1D LTI system <img src="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller19.png" alt="../../../../../fig/mpt/modules/ui/@MPCController/mpccontroller19.png">
      <pre class="programlisting">sys = LTISystem('A', 0.9, 'B', 1)</pre>
<pre class="programlisting">LTISystem with 1 state, 1 input, 0 outputs
</pre>Construct the MPC controller<pre class="programlisting">ctrl = MPCController(sys)</pre>
<pre class="programlisting">MPC controller (no prediction horizon defined)
</pre>Add constraints<pre class="programlisting">
		ctrl.model.x.min = -1; ctrl.model.x.max = 1;
		ctrl.model.u.min = -1; ctrl.model.u.max = 1;
	</pre>
<pre class="programlisting"></pre>Add penalties (we use squared two-norm with unity
    weights here)<pre class="programlisting">
		ctrl.model.x.penalty = QuadFunction(1);
		ctrl.model.u.penalty = QuadFunction(1);
	</pre>
<pre class="programlisting"></pre>Specify the prediction horizon<pre class="programlisting">ctrl.N = 4;</pre>
<pre class="programlisting"></pre>Compute the optimal control action for the initial state <tt>x0=0.5</tt>
      <pre class="programlisting">
		x0 = 0.5;
		u = ctrl.evaluate(x0)
	</pre>
<pre class="programlisting">
u =

        -0.268049612898345

</pre>We can also ask for the full open-loop predictions:<pre class="programlisting">
		[u, feasible, openloop] = ctrl.evaluate(x0)
	</pre>
<pre class="programlisting">
u =

        -0.268049612898345


feasible =

     1


openloop = 

    cost: 0.370622325804255
       U: [-0.268049612898345 -0.0956658064407663 -0.0306402938778255 -3.46944695195361e-18]
       X: [0.5 0.181950387101655 0.0680895419507233 0.0306402938778255 0.0275762644900429]
       Y: [0x4 double]

</pre>Convert the controller to an explicit form<pre class="programlisting">expctrl = ctrl.toExplicit()</pre>
<pre class="programlisting">mpt_plcp: 1 regions
Explicit MPC controller (horizon: 4, regions: 1)
</pre>
<h2>See Also</h2>
<a href="../@EMPCController/empccontroller.html">empccontroller</a><p></p>
<table class="nav" summary="Navigation aid" border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top">
<td align="left" width="20">
<a href="evaluate.html" class="button">&#9664;</a>  </td>
<td align="left">evaluate</td>
<td>  </td>
<td align="right">toyalmip</td>
<td align="right" width="20"><a href="toyalmip.html" class="button">&#9654;</a></td>
</tr></table>
<br><p>©  <b>2003-2013</b>     Michal Kvasnica: STU Bratislava,    <a href="mailto:michal.kvasnica@stuba.sk">michal.kvasnica@stuba.sk</a></p>
</body>
</html>
